package com.wjggy.core.service.user.Impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.wjggy.core.common.dbtools.DaoUtils;
import com.wjggy.core.common.page.Page;
import com.wjggy.core.entities.User;
import com.wjggy.core.service.user.ManageUserService;


 /**
 *  <p>Description:  用户管理</p>
 *  <p>Copyright:Copyright (c) 2012  </p>
 *  <p>Company:wjggy  </p>
 *  @author xiaofan.yu  
 *  @date   2012-1-9 上午10:44:03    
 *  @project  wjggy
 *  @version  1.0.0
 *  @see   
 *  @since 1.6 
 */
@Service("manageUserService")
public class ManageUserServiceImpl implements ManageUserService {
	private static final Logger log = Logger.getLogger(ManageUserServiceImpl.class);
	@Resource(name="daoUtils")
	private DaoUtils daoUtils;
	@Override
	public int addUser(HttpServletResponse resonse, User admin,
			String addAuthCode) {
		try {
			Integer count=0;//(Integer) daoUtils.findObject("user.queryEmailCount", admin.getUseremail());
			if(count==0){
				daoUtils.add("user.insert", admin);
				return 1;
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.error(e.getMessage());
		}
		return 0;
	}
	
	@SuppressWarnings("unchecked")
	public List<User> getUsers(Page page){
		return daoUtils.findRows("user.queryAll",null,page);
	}
	
	public boolean saveUser(User user){
		int i=daoUtils.add("user.insert", user);
		return i==1?true:false;
	}
	public User getUserById(Long id){
		return (User) daoUtils.findObject("user.queryByID", id);
	}
	
	public boolean updateUser(User user){
		int i=daoUtils.update("user.update", user);
		return i==1?true:false;
	}
	
	public boolean deleteUser(Long id){
		int i=daoUtils.delete("user.delete", id);
		return i==1?true:false;
	}
}

